/*用户不分页列表,作者:高振中,日期:2021-02-23 15:04:24*/
<template>
  <el-dialog title="关联用户" :visible.sync="show">
    <el-form :inline="true">
      <el-form-item label="机构名称"> <el-input placeholder="请输入机构名称" size="mini" v-model="form.deptName"></el-input> </el-form-item>
      <el-form-item label="用户名"> <el-input placeholder="请输入用户名" size="mini" v-model="form.name"></el-input> </el-form-item>
      <el-form-item> <el-button icon="search" @click="loadData()" title="根据输入的条件查询" size="mini">查询</el-button> <el-button @click="doReset()" title="重置" size="mini">重置</el-button> </el-form-item>
      <el-row :gutter="10">
        <el-col :span="6" v-for="user in dataList" :key="user.id">
          <el-checkbox v-model="user.checked">{{ "(" + user.deptName + ")-" + user.name }}</el-checkbox>
        </el-col>
      </el-row>
    </el-form>
    <div style="text-align: right"><el-button @click="show = false" size="mini">取消</el-button> <el-button type="primary" @click="save()" size="mini">确定</el-button></div>
  </el-dialog>
</template>
<script>
import { pageMix } from "@/common/page";
export default {
  mixins: [pageMix],
  data() { return { show: false, }; },
  methods: {
    //查询参数
    initForm() { return { deptName: null, /*机构ID*/ name: null, /*帐号*/ roleId: null, }; },
    //清空查询参数,执行查询
    doReset() { this.form = { ...this.initForm(), roleId: this.form.roleId }; this.loadData(); },
    //显示窗口
    showUsers(roleId) { this.form.roleId = roleId; this.loadData(); this.show = true; },
    //请求人员列表
    loadData() {
      this.rq.post("/roleUser/list", this.form).then((res) => { if (res.code == 200) this.dataList = res.data; else this.$message.error(res.msg); });
    },
    //授权
    save() {
      const param = this.dataList .filter((i) => i.checked).map((i) => { return { roleId: this.form.roleId, userId: i.userId }; });
      this.rq.post("/roleUser/save?roleId=" + this.form.roleId, param).then((res) => {
        if (res.code == 200) { this.$message.success("授权成功"); this.show = false; } else this.$message.error(res.msg);
      });
    },
  },
};
</script>
<style scoped lang="scss"></style>
